<link type="text/css" rel="stylesheet" href="<?=base_url()?>css/vote.css" />
<script type="text/javascript">
	function sortMe(event_id,sort_value){
		window.location="<?=site_url("vote/voteDetail")?>"+"/"+event_id+"/"+sort_value;
	}
</script>
<div id="border">
<form action="<?=site_url('vote/submitVote')?>" method="post">   
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
     <td valign="top">       
        <table width="705" border="0" align="center" id="usertitle">
          <tr>
            <td><h3><?=$Z_TRANS->value('title_vote_detail')?></h3></td>
            <td align="right">
            		
            </td>
          </tr>
        </table>
        <div id="content">
        <div class="user_line_border_top" style="height:3px; font-size:15px; padding-left:10px; padding-top:10px; padding-right:6px; text-align:left">
        </div>
        <div style="margin:10px auto;"></div>
        <table border="0" cellpadding="0" cellspacing="" width="100%">
    	<?php 
    		$cat_desc="";
    		foreach ($items->result_array() as $myitem){
        			$cat_desc=$myitem['vote_item_cat_desc'];
    		}
    	foreach ($events->result_array() as $event){
    	$max_message=(isset($max_error))?$max_error:"";
    	$event_id=$event['event_id'];
    	?>
        <tr>
          <td width="80%" valign="top" colspan="2"><input type="hidden" name="txteventid" id="txteventid" value="<?=$event['event_id']?>">&nbsp;&nbsp;<b class="vote_topic" style="color: blue;"><?=htmlspecialchars($event['top_name'])?></b><p align="justify" style="padding-left: 15px;"><?=nl2br(htmlspecialchars($event['top_desc']))?></p></td>
        </tr>
        <?php 
        	$byCount="";
        	$byAlpha="";
        	if(isset($sort) && $sort!=1){
        		$byCount="selected";
        	}else if(isset($sort) && $sort==1){
        		$byAlpha="selected";
        	}
    	}
        ?>

        <tr>
        	<td colspan="2">
        		<table border="0" cellpadding="0" cellspacing="0" width="100%">
	         		<tr>
                         <td colspan="3" align="right" height="30">
							 <?=$Z_TRANS->value('title_sort_by')?> :
                            <select onchange="javascript:sortMe('<?=$event_id?>',this.value)">
                             <option value="0" <?=$byCount?>>Count (Highest)</option>
                             <option value="1" <?=$byAlpha?>><?=htmlspecialchars ($cat_desc)?> (Alphabetic)</option>
                            </select>
                          </td>
                     </tr>  
					  <?php 
                          if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!="" && $voting==1){
                              
                      ?>        
                      <tr align="center" style="font-size: 13px; background-color: #CCC" class="vote_header">
                          <td width="70%" align="left"  height="25" style="border-right: solid 0px;">&nbsp;&nbsp;&nbsp;<b><?=htmlspecialchars($cat_desc)?></b></td>
                          <td align="center"  width="15%"><b>Vote</b></td>
                          <td width="15%"><b>Count</b></td>
                      </tr>
                      <?php 
                          
                          }else{
                      ?>
                      <tr align="center" bgcolor="#EFEFEF" class="vote_header">
                          <td width="85%" align="left" colspan="2" height="25">&nbsp;&nbsp;&nbsp;<b><?=htmlspecialchars($cat_desc)?></b></td>
                          <td width="15%"><b>Count</b></td>
                      </tr>
                      <?php 
                          }
                      ?>
                    <?php 
                        $this->load->model('vote_model');
                        $result=0;
                        $i=0;
                        $color="#EFEFEF";
                        foreach ($items->result_array() as $item){
                            $i++;
                            $foundme=false;
                            $color=($color=="#EFEFEF")?"#FFF":"#EFEFEF";
                                if($max_message!=""){
                                    for($x=0;$x<count($checkeditems);$x++){
                                        if($checkeditems[$x]==$item['vote_item_id']){
                                            $foundme=true;
                                            break;
                                        }
                                    }
                                }else{
                                   foreach($curitems->result_array() as $myitem ){
                                        if($myitem['vote_item_id']==$item['vote_item_id']){
                                            $foundme=true;
                                            break;
                                        }
                                	}
                                   /* foreach($curevent->result_array() as $myevent ){
                                        if($myevent['vote_item_id']==$item['vote_item_id']){
                                            $foundme=true;
                                            break;
                                        }
                                	}*/
                            }
                            $checkme=($foundme==true)?"checked":"";
                            if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!="" && $voting==1){
                        ?>
                        <tr bgcolor="<?=$color?>" style="font-size: 13px;">
                            <td height="30">&nbsp;<?=$i.". ".htmlspecialchars($item['vote_item_desc'])?></td>
                            <td align="center"><input type="checkbox" <?=$checkme?> name="items[]" value="<?=$item['vote_item_id']?>"></td>
                            <td align="center" ><?=htmlspecialchars($item['vote_count'])?></td>
                        </tr>
                    <?php 
                            }else{
                    ?>
                        <tr bgcolor="<?=$color?>" style="font-size: 13px;">
                            <td height="30" colspan="2">&nbsp;<?=$i.". ".htmlspecialchars($item['vote_item_desc'])?></td>
                            <td align="center" ><?=htmlspecialchars($item['vote_count'])?></td>
                        </tr>
                    <?php 
                            }
                        }
                    ?>	
                        <tr>
                           <td colspan="3"></td>
                        </tr>
                        <tr><td colspan="3">&nbsp;</td></tr>
                        <?php if($max_message!=""){
                        ?>
                        <tr><td colspan="3" height="50"><font color="red"><?=$max_message." ".strtolower($cat_desc)."(s)"?></font></td></tr>
                        <?php 
                        }
                        if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!=""){
                        ?>
                        <tr><td colspan="3">&nbsp;</td></tr>
                        <tr>
                        	<td colspan="2">&nbsp;&nbsp;<input type="submit" class="kh_button" value="<?=$Z_TRANS->value('title_vote_now')?>" style="background-color: #006295;border:solid 1px #009966;color:#FFF; height: 23px;cursor: pointer;"></td>
                        	<td align="center"><a href="<?=site_url("vote")?>"><?=$Z_TRANS->value('title_back')?></a></td>
                        </tr>
                        <?php 
                        }else{
                        ?>
                            <tr><td colspan="3">&nbsp;</td></tr>
	                        <tr>
	                        	<td colspan="2"></td>
	                        	<td align="center"><a href="<?=site_url("vote")?>"><?=$Z_TRANS->value('title_back')?></a></td>
	                        </tr>
                        <?php 
                        }
                        ?>
                    </table>
                </td>
            </tr>
        </table>
                
        <br />       
        </div>
        </td>
        <td width="254" valign="top">
			<?php include APPPATH."views/templates/common/right_content.php"; ?>
         </td>
         
      </tr>
  </table>
  </form>
</div>
